/*
 * Copyright (C) 2015 Daniel Uppenkamp
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.maurersmarbles.states;

import com.googlecode.maurersmarbles.GameState;
import com.googlecode.maurersmarbles.InputEvent;
import com.googlecode.maurersmarbles.RGB;
import com.googlecode.maurersmarbles.Screen;
import com.googlecode.maurersmarbles.drawables.Drawable;
import com.googlecode.maurersmarbles.drawables.RectangleDrawable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Daniel Uppenkamp
 */
public class IntroState implements State {

    /**
     * The IntroState instance.
     */
    private static final IntroState INSTANCE = new IntroState();
    /**
     * The duration to display the intro (in millis).
     */
    protected static final long INTRO_DURATION = 2000;

    /**
     * Creates a new IntroState.
     */
    private IntroState() {
        // do nothing
    }

    /**
     * Returns the drawables to draw on the screen.
     *
     * @param screen the screen
     * @return the drawables to draw on the screen
     */
    protected Collection<Drawable> getDrawables(Screen screen) {

        Collection<Drawable> drawables = new ArrayList();

        drawables.add(new RectangleDrawable(0, 0, screen.getWidth(), screen.getHeight(), RGB.WHITE, true));

        // TODO Add the drawables for the intro
        return drawables;

    }

    /**
     * Returns the IntroState instance.
     *
     * @return the IntroState instance
     */
    public static IntroState getInstance() {
        return INSTANCE;
    }

    @Override
    public State enter(Screen screen, GameState gameState) {

        // check to see if we have a screen
        if (screen != null) {

            // get the drawables and draw them on the screen
            screen.draw(getDrawables(screen));

            try {
                Thread.sleep(INTRO_DURATION);
            }
            catch (InterruptedException ex) {
                // TODO Create a logger at the class level?
                Logger.getLogger(IntroState.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        // advance to the main menu
        return MainMenuState.getInstance();

    }

    @Override
    public State handleInputEvent(Screen screen, GameState gameState, InputEvent inputEvent) {
        // do nothing and return null to stay in this state
        return null;
    }

    @Override
    public void handleResizeEvent(Screen screen, GameState gameState, int width, int height) {

        // check to see if we have a screen
        if (screen != null) {

            // get the drawables and draw them on the screen
            screen.draw(getDrawables(screen));

        }

    }

}
